package reflex.learning02;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @program JavaBase
 * @description:    获取其他东西
 * @author: zhanglu
 * @create: 2019-06-08 12:48:00
 */
public class TestOthers {

    @Test
    public void test01(){
        Class clazz = Person.class;
        //获取运行时类的父类
        Class superClass = clazz.getSuperclass();
        System.out.println(superClass);

        //获取带泛型的父类
        Type type1 = clazz.getGenericSuperclass();
        System.out.println(type1);

        //获取实现的接口
        Type[] types1 = clazz.getGenericInterfaces();
        for(Type t : types1){
            System.out.println(t);
        }

        //获取父类的泛型
        ParameterizedType param = (ParameterizedType)type1;
        Type[] types2 = param.getActualTypeArguments();
        for(Type t : types2){
            System.out.println(t);
        }

        //获取所在的包
        Package pack = clazz.getPackage();
        System.out.println(pack);

        //获取关于类的注解(RUNTIME)
        Annotation[] anns = clazz.getAnnotations();
        for (Annotation a : anns){
            System.out.println(a);
        }

    }
}
